package com.bicon.botu.mall.base.controller;

import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import com.bicon.botu.mall.base.common.MallHomePageConstants;
import com.bicon.botu.mall.base.dto.ChannelDto;
import com.bicon.botu.mall.base.service.IChannelGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 栏目商品 前端控制器
 *
 * @author 张凡
 * @date 2017/7/19 下午 14:49
 */
@RestController
@CrossOrigin
@RequestMapping("/V1.0.0/homePage/channelGoods")
public class ChannelGoodsController extends BaseController {
    @Autowired
    IChannelGoodsService iChannelGoodsService;

    /**
     * 添加频道商品
     *
     * @param goodsId     商品id
     * @param channelType 频道类型： 1-猜你喜欢 2-新品首发 3-人气推荐
     * @return
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public BaseResult add(@RequestParam("goodsId") String goodsId,
                          @RequestParam("channelType") Integer channelType) {
        return iChannelGoodsService.add(goodsId, channelType);

    }

    /**
     * 修改频道商品排序
     *
     * @param goodsIdJson 商品id集合
     * @param channelType 频道类型：1-猜你喜欢 2-新品首发 3-人气推荐
     * @return
     */
    @RequestMapping(value = "/updateSort", method = RequestMethod.POST)
    public BaseResult updateSort(@RequestParam("goodsIdJson") String goodsIdJson,
                                 @RequestParam("channelType") Integer channelType) {
        return iChannelGoodsService.updateSort(goodsIdJson, channelType);
    }

    /**
     * 删除频道商品
     *
     * @param goodsId     商品id
     * @param channelType 频道类型： 1-猜你喜欢 2-新品首发 3-人气推荐
     * @return
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public BaseResult delete(@RequestParam("goodsId") String goodsId,
                             @RequestParam("channelType") Integer channelType) {
        return iChannelGoodsService.delete(goodsId, channelType);
    }

    /**
     * 查询频道和频道商品
     *
     * @param channelType 频道类型： 1-猜你喜欢 2-新品首发 3-人气推荐
     * @return
     */
    @RequestMapping(value = "/getChannelGoods", method = RequestMethod.POST)
    public BaseResult getChannelGoods(@RequestParam("channelType") Integer channelType) {
        //后台从数据库查
        ChannelDto channelDto = iChannelGoodsService.getChannelGoods(channelType);
        return new BaseResult(MallHomePageConstants.RESPONSE_CODE_200, MallHomePageConstants.RESPONSE_MESSAGE_200, channelDto);
    }

    /**
     * 修改频道商品
     *
     * @param id          主键id
     * @param goodsId     商品id
     * @param channelType 频道类型： 1-猜你喜欢 2-新品首发 3-人气推荐
     * @return
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public BaseResult update(@RequestParam("id") Integer id,
                             @RequestParam("goodsId") String goodsId,
                             @RequestParam("channelType") Integer channelType) {
        return iChannelGoodsService.update(id, goodsId, channelType);
    }

}
